import { request,SET_TOKEN,GET_TOKEN } from "@/utils";
import { createSlice } from "@reduxjs/toolkit";

const userStore=createSlice({
 name:'user',
initialState:{
    token:localStorage.getItem("token"),
    userInfo:{},
    selectOption:[]
},
reducers:{
    setToken(state,action){      
        SET_TOKEN(action.payload)
        state.token = GET_TOKEN()
    },
    setUserName(state,action){
        state.userInfo = action.payload
    },
    setSelectOption(state,action){
        state.selectOption = action.payload
    }
}
})
// function tologin(data){
    // return async (dispatch)=>{
        // const res = await request.post('/authorizations', data)
    // dispatch(setToken(res.data.token))
    // }
// }

const {setToken,setUserName,setSelectOption}=userStore.actions
export {setToken,setUserName,setSelectOption}
const userReducer = userStore.reducer
export default userReducer